<!DOCTYPE html>
<html>
<!--
Copyright 2012 The Closure Library Authors. All Rights Reserved.

Use of this source code is governed by the Apache License, Version 2.0.
See the COPYING file for details.
-->
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Closure Unit Tests - goog.labs.classdef</title>
<script src="../../base.js"></script>
<script>
  goog.require('goog.labs.classdef');
  goog.require('goog.testing.jsunit');
</script>
</head>
<body>
<script>

function testSuper() {
  /** @constructor */
  function SomeSuper() {};

  var SomeClass = goog.labs.classdef.defineClass(SomeSuper, {
    /** @constructor */
    constructor: function() {}
  });

  assertTrue(new SomeClass() instanceof SomeClass);
  assertTrue(new SomeClass() instanceof SomeSuper);
}

function testPrototypeProp() {
  var SomeClass = goog.labs.classdef.defineClass(null, {
    /** @constructor */
    constructor: function(){
    },
    trueMethod: function(){ return true; }
  });

  assertEquals(new SomeClass().falseProp, false);
  assertEquals(new SomeClass().trueMethod(), true);
}

function testInstanceProp() {
  var SomeClass = goog.labs.classdef.defineClass(null, {
    /** @constructor */
    constructor: function(){
      this.falseProp = false;
    }
  });

  assertEquals(new SomeClass().falseProp, false);
}

function testPrototypeProp() {
  var SomeClass = goog.labs.classdef.defineClass(null, {
    /** @constructor */
    constructor: function(){
    },
    trueMethod: function() {
      return true;
    }
  });

  assertEquals(new SomeClass().trueMethod(), true);
  assertEquals(SomeClass.prototype.trueMethod(), true);
}

function testStaticProp() {
  var SomeClass = goog.labs.classdef.defineClass(null, {
    /** @constructor */
    constructor: function(){
    },
    statics: {
      someProp: 100
    }
  });

  assertEquals(new SomeClass().statics, undefined);
  assertEquals(new SomeClass().someProp, undefined);
  assertEquals(SomeClass.someProp, 100);
}

function testStaticPropFn() {
  var SomeClass = goog.labs.classdef.defineClass(null, {
    /** @constructor */
    constructor: function() {
    },
    statics: function(cls) {
      cls.someProp = 100;
    }
  });

  assertEquals(new SomeClass().statics, undefined);
  assertEquals(new SomeClass().someProp, undefined);
  assertEquals(SomeClass.someProp, 100);
}

</script>
</body>
</html>
